<?php 
	 //Connects to your Database 
	 $db_host = 'localhost';
	 $db_user = 'function';
	 $db_pwd = 'w9ak4X1l0Y';

	 $database = 'function_a5110060';

	 $method_to_call = $_GET['toCall'];

	 $slots_array = array();

	 $con = mysql_connect($db_host, $db_user, $db_pwd); 
	 mysql_select_db($database,$con) or die(mysql_error()); 
	
	 if(strcmp($method_to_call, "getDates")==0){
		
		$functionHall_id = $_GET['id'];
		getDates($functionHall_id);
	 }

	 if(strcmp($method_to_call, "getSlots")==0){
		 $functionHall_id = $_GET['id'];
		 $hallDate = $_GET['date'];
		getSlots($functionHall_id,$hallDate);
	 }

	function getDates($hallId)
	{
		
		 $data = mysql_query("SELECT DISTINCT dates FROM Availability_Details WHERE function_hall_id = ".$hallId)
		 or die(mysql_error()); 

		global $slots_array;
		 $slots_array = array();
		//echo $data;
		while($info = mysql_fetch_array( $data )) 
		 { 
			
			$row_array['optionValue'] = $info['dates'];
			$row_array['optionDisplay'] = $info['dates'];
			array_push($slots_array,$row_array);

		 }
	}

	function getSlots($hallId,$hallDate)
	{
		 $data = mysql_query("SELECT ad.slot FROM Availability_Details ad WHERE ad.function_hall_id =".$hallId." AND ad.dates = '".$hallDate."'")
		 or die(mysql_error()); 

		global $slots_array;
		 $slots_array = array();
		//echo $data;
		while($info = mysql_fetch_array( $data )) 
		 { 
			
			$row_array['optionValue'] = $info['slot'];
			$row_array['optionDisplay'] = $info['slot'];
			array_push($slots_array,$row_array);

		 }
	}

	echo json_encode($slots_array);
?> 